package cn.edu.neusoft.yuejian13.yuejian_13.activity;


import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.yuejian13.yuejian_13.R;
import cn.edu.neusoft.yuejian13.yuejian_13.javaBean.Train;
import cn.edu.neusoft.yuejian13.yuejian_13.listener.TListener;
import cn.edu.neusoft.yuejian13.yuejian_13.model.TrainModel;



public class TrainDetailActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView tr_name,tr_intro,tr_time,tr_price;
    private ImageView tr_img,back;
    private Button signup;
    private SharedPreferences sp;
    private Context mContext;



    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_traindetails);
        initViews();
        initEvent();
        TrainModel trainModel = new TrainModel();
        trainModel.trainDetails(getIntent().getIntExtra("trainid",1),listener);

    }

    TListener<Train> listener = new TListener<Train>() {
        @Override
        public void onResponse(Train train) {
            tr_name.setText(train.getTrain_name());
            tr_intro.setText(train.getIntro());
            tr_price.setText(Integer.toString(train.getPrice()));
            tr_time.setText(train.getTime());
            Picasso.with(TrainDetailActivity.this)
                    .load("http://10.0.2.2/yuejian10/public/static/asstes/images/"+train.getPic())
                    .placeholder(R.drawable.ic_default_img)
                   // .memoryPolicy(MemoryPolicy.NO_CACHE)
                    .into(tr_img);

        }

        @Override
        public void onFail(String msg) {

        }
    };



    private void initViews(){
        tr_name = (TextView)findViewById(R.id.tr_name);
        tr_intro = (TextView)findViewById(R.id.tr_intro);
        tr_time = (TextView)findViewById(R.id.tr_time);
        tr_price = (TextView)findViewById(R.id.tr_price);

        tr_img = (ImageView)findViewById(R.id.tr_img);
        back = (ImageView) findViewById(R.id.tr_back);
        signup = (Button)findViewById(R.id.train_signup);
    }

    private void initEvent(){
        back.setOnClickListener(this);
        signup.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.tr_back:
                finish();
                break;

        }

    }
}
